import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI, { Loading } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/element-theme-#1D6AD2/index.css'
import './assets/less/index.less'

import { MdvUI } from '@/components/index'
import httpService from '@/ddd/http.service'
import localStorageService from '@/ddd/localStorage.service'
Vue.config.productionTip = false

Vue.use(ElementUI)

Vue.use(MdvUI)

Vue.http = Vue.prototype.$http = httpService
Vue.local = Vue.prototype.$local = localStorageService
Vue.loading = Vue.prototype.$loading = Loading.service
/** 权限判断 */
Vue.isPrem = Vue.prototype.$isPrem = (prems) => {
  const allPermission = '*:*:*'
  const permissions = localStorageService.getItem('permissions') || []

  if (permissions.length === 0) {
    return true
  }

  if (prems && prems instanceof Array && prems.length > 0) {
    const hasPermissions = permissions.some(prem => {
      return allPermission === prem || prems.includes(prem)
    })

    return hasPermissions
  } else {
    throw new Error('请设置操作权限标签值')
  }
}

Vue.sleep = Vue.prototype.$sleep = (time) => {
  return new Promise((resolve) => setTimeout(resolve, time));
}

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
